package com.lzw.controller;

import com.alibaba.fastjson.JSONArray;
import com.lzw.pojo.Cla;
import com.lzw.service.ClaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/ClaController")
public class ClaController {
    @Autowired
     private ClaService cs;
    @ResponseBody//标注请求为ajax请求，页面不在跳转，只传递数据
    @PostMapping(value ="/getAllCla",produces ="application/json;charset=utf-8")
    public String getAllCLa(){
        //取调存转
        List<Cla> clas=cs.getAllCla();
        //转换为json类型:{"cid":1,"cname":"移动开发班","content":""}
        String jsonStr=JSONArray.toJSONString(clas);
        //把字符串传递到AJAX里
        return jsonStr;
    }
}
